package pl.donajski.magisterka;

import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;

public class SubstitutionAddedNodeTabuList implements ITabuList {

	public SubstitutionAddedNodeTabuList(int size) {
		this.mSize = size;
	}
	
	public void add(IMove m) {
		Node n = ((Substitution)m).getNewNode();
		if(this.mList.size() == this.mSize) {
			mSet.put(mList.peek(), mSet.get(mList.poll()) - 1);
		}
		
		if(mSet.containsKey(n)) {
			mSet.put(n, mSet.get(n) + 1);
		} else {
			mSet.put(n, 1);
		}

		mList.add(n);
	}

	public boolean contains(IMove m) {
		Node n = ((Substitution)m).getOldNode(); 
		
		if(mSet.containsKey(n))
			return mSet.get(n) > 0;
			
		return false;
		
	}
	
	
	HashMap<Node, Integer> mSet = new HashMap<Node, Integer>();
	LinkedList<Node> mList = new LinkedList<Node>();
	private int mSize;

}
